package com.self.war.view;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.self.war.presenter.LoginPresenter;
import com.self.war.widgets.LoginForm;
import com.vaadin.navigator.View;
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
import com.vaadin.ui.CustomLayout;
import com.vaadin.ui.Notification;
import com.vaadin.ui.VerticalLayout;

@SuppressWarnings("serial")
@Component
public class LoginView extends CustomLayout implements View {

	@Autowired
	LoginPresenter loginPresenter;

	@Autowired
	LoginForm loginForm;

	/**
	 * inject the view reference within the presenter object to avoid bean
	 * cyclic dependency
	 */
	@PostConstruct
	private void init() {
		loginPresenter.setView(this);
		initLayout();

	}

	public LoginView() {
		super("mylayout");

	}

	public static final String VIEW_NAME = "login";

	@Override
	public void enter(ViewChangeEvent event) {
		Notification.show("Loogin view");
	}

	private void initLayout() {
		final VerticalLayout content = new VerticalLayout();
 		addComponent(content, "content");
 		content.addComponent(loginForm);
		loginForm.setSizeFull();
		loginForm.setVisible(true);

	}

	public LoginPresenter getLoginPresenter() {
		return loginPresenter;
	}

	public void setLoginPresenter(LoginPresenter loginPresenter) {
		this.loginPresenter = loginPresenter;
	}

}
